﻿namespace ZhhbSoft.Data.Criterion
{
    public class ExpressionCollection : NodeCollection
    {
        public new Expression this[int index]
        {
            get { return (Expression)base[index]; }
        }
        public Expression this[string Name]
        {
            get
            {
                return this[Name, true];
            }
        }
        public Expression this[string Name, bool AutoAddItem]
        {
            get
            {
                foreach (Expression node in _nodes)
                {
                    if (node.Attributes["name"] == Name)
                    {
                        return (Expression)node;
                    }
                }
                if (AutoAddItem)
                {
                    Expression itemNew = new Expression();
                    Add(itemNew);
                    itemNew.Name = Name;
                    return itemNew;
                }
                return null;
            }

        }
    }
}